using Microsoft.AspNetCore.Mvc;
using Sheep_Breeding.ErrorCode;
using Sheep_Breeding.Write.Api.DTOs;
using Sheep_Breeding.Write.Api.OperationServices.IServices;
using System;
using System.Collections.Generic;
using System.Threading.Tasks;

namespace Sheep_Breeding.Write.Api.Controllers
{
    /// <summary>
    /// 羊只死亡记录API
    /// </summary>
    [ApiController]
    [Route("api/[controller]")]
    public class SheepDeathController : ControllerBase
    {
        private readonly ISheepDeathServices sheepDeathServices;

        public SheepDeathController(ISheepDeathServices sheepDeathServices)
        {
            this.sheepDeathServices = sheepDeathServices;
        }

        /// <summary>
        /// 添加羊只死亡记录
        /// </summary>
        [HttpPost("add")]
        public async Task<IActionResult> AddSheepDeath([FromBody] AddSheepDeathDto dto)
            => Ok(await sheepDeathServices.AddSheepDeath(dto));

        /// <summary>
        /// 删除羊只死亡记录
        /// </summary>
        [HttpDelete("delete/{id}")]
        public async Task<IActionResult> DeleteSheepDeath(long id)
            => Ok(await sheepDeathServices.DeleteSheepDeath(id));

        /// <summary>
        /// 修改羊只死亡记录
        /// </summary>
        [HttpPut("update")]
        public async Task<IActionResult> UpdateSheepDeath([FromBody] UpdateSheepDeathDto dto)
            => Ok(await sheepDeathServices.UpdateSheepDeath(dto));

        /// <summary>
        /// 查询所有羊只死亡记录
        /// </summary>
        [HttpGet("all")]
        public async Task<IActionResult> GetAllSheepDeaths()
            => Ok(await sheepDeathServices.GetAllSheepDeaths());

        /// <summary>
        /// 按条件查询羊只死亡记录
        /// </summary>
        [HttpGet("search")]
        public async Task<IActionResult> SearchSheepDeaths(string earNumber, DateTime? deathDate)
            => Ok(await sheepDeathServices.SearchSheepDeaths(earNumber, deathDate));
    }
} 